package com.uam.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.uam.db.model.entity.DataLayerBc;
import com.uam.service.IDataLayerBcService;
import com.uam.web.common.model.PageData;
import com.uam.web.common.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 图层Controller
 *
 * @author uam
 * @date 2023-11-22
 */
@Controller
@RequestMapping("/bc/info/")
@Api(tags = "20241103")
public class LayerBcController extends BaseController {

    @Autowired
    private IDataLayerBcService dataLayerService;

    @ApiOperation(value = "查看数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页"),
            @ApiImplicitParam(name = "pageSize", value = "分页条数"),
    })
    @GetMapping("/list")
    @ResponseBody
    public Result<PageData<DataLayerBc>> list(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                              @RequestParam(required = false, defaultValue = "20") Integer pageSize,
                                              @RequestParam(required = false) String layerName
                                            ) {
        DataLayerBc dataLayerBc=new DataLayerBc();
        dataLayerBc.setLayerName(layerName);
        Page<DataLayerBc> page = new Page(pageNum, pageSize);
        IPage<DataLayerBc> pageResult = dataLayerService.selectDataLayerList(page, dataLayerBc);
        return okPageData(pageResult);
    }

    /**
     * 数据记录添加
     */
    @ApiOperation(value = "数据添加")
    @PostMapping("/add")
    @ResponseBody
    public Result add(@RequestBody DataLayerBc dataLayer) {
      return toResult(dataLayerService.insertDataLayer(dataLayer));
    }

    /**
     * 数据记录添加
     */
    @ApiOperation(value = "修改数据")
    @PostMapping("/update")
    @ResponseBody
    public Result update(@RequestBody DataLayerBc dataLayer) {
        return toResult(dataLayerService.updateDataLayer(dataLayer));
    }

    @ApiOperation(value = "删除数据")
    @PostMapping("/delete")
    @ResponseBody
    public Result delete(Long id) {
        return toResult(dataLayerService.deleteDataLayerById(id));
    }

    @ApiOperation(value = "查找数据")
    @PostMapping("/find/id")
    @ResponseBody
    public Result<DataLayerBc> selectById(Long id) {
        return Result.ok(dataLayerService.selectDataLayerById(id));
    }
}
